package cn.codeartist.springboot.example.controller;

import cn.codeartist.springboot.component.rocketmq.proxy.MessageEntity;
import cn.codeartist.springboot.component.rocketmq.proxy.RocketMQProducer;
import cn.codeartist.springboot.example.entity.People;
import org.apache.rocketmq.client.producer.SendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * jnai
 *
 * @author 艾江南
 * @date 2020/8/14
 */
@RestController
@RequestMapping("rocketmq")
public class RocketMQController {

    @Lazy
    @Autowired
    private RocketMQProducer rocketMqProducer;

    @GetMapping("send")
    public ResponseEntity<SendResult> send() {
        People people = new People();
        people.setAge(25);
        people.setName("艾江南");
        MessageEntity message = new MessageEntity("CODEARTIST_CN_TOPIC", "CODEARTIST_CN_TAG", people);
        SendResult sendResult = rocketMqProducer.send(message);
        return ResponseEntity.ok(sendResult);
    }
}
